import AutoChart from '@/components/Echarts/AutoChart';
import { graphic } from 'echarts'
// @ts-ignore
import { medicinenewvisit } from '@/services/api';
import { BorderBox1 } from '@jiaminghi/data-view-react';
import { useEffect } from 'react';
import { useImmer } from 'use-immer';
import './Chart4.less';

const Chart4: React.FC = () => {
  const [options, setOptions] = useImmer({
    legend: {
      data: ['中医就诊', '中西结合'],
      textStyle: {
        color: '#fff'
      } 
    },
    tooltip: {},
    xAxis: {
      data: [],
      splitLine: {
        show: false,
      },
    },
    grid: {
      top: '12%',
      left: '7%',
      right: '7%',
      bottom: '8%',
      containLabel: true,
    },
    yAxis: {},
    series: [
      {
        name: '中医就诊',
        type: 'line',
        data: [],
        stack: 'Total',
        smooth: true,
        lineStyle: {
          width: 0,
        },
        // showSymbol: false,
        areaStyle: {
          opacity: 0.8,
          color: new graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: 'rgb(128, 255, 165)',
            },
            {
              offset: 1,
              color: 'rgb(1, 191, 236)',
            },
          ]),
        },
        emphasis: {
          focus: 'series',
        },
        animationDelay: function (idx) {
          return idx * 10;
        },
      },
      {
        name: '中西结合',
        type: 'line',
        data: [],
        stack: 'Total',
        smooth: true,
        lineStyle: {
          width: 0,
        },
        // showSymbol: false,
        areaStyle: {
          opacity: 0.8,
          color: new graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: 'rgb(0, 221, 255)',
            },
            {
              offset: 1,
              color: 'rgb(77, 119, 255)',
            },
          ]),
        },
        emphasis: {
          focus: 'series',
        },
        animationDelay: function (idx) {
          return idx * 10 + 100;
        },
      },
    ],
    animationEasing: 'elasticOut',
    animationDelayUpdate: function (idx) {
      return idx * 5;
    },
  });

  useEffect(() => {
    medicinenewvisit().then((res) => {
      setOptions((draft) => {
        draft.xAxis.data = res.data.map((i) => i.name);
        draft.series[0].data = res.data.map((i) => Number(i.value.split('-')[0]));
        draft.series[1].data = res.data.map((i) => Number(i.value.split('-')[1]));
      });
    });
  }, []);
  return (
    <>
      <div className="'marginb-10">
        <BorderBox1 color={['#396993', '#396993']}>
          <div className="echart_title">
            <div>中医就诊趋势</div>
          </div>
          <div className="padding-5" style={{ height: 294 }}>
            <AutoChart option={options as any}></AutoChart>
          </div>
        </BorderBox1>
      </div>
    </>
  );
};
export default Chart4;
